/**
 * Created by fkjslee on 2018/3/15.
 */


function chooseDiscrete() {
    var agentName = $("#agentsName").combobox("getText");
    var fieldName = $("#fieldsName").combobox("getText");
    var fieldType = "discrete";
    var newValue = $("#discreteValues").combobox("getText");
    $("#tableParam").datagrid("appendRow", {
        thAgentName: agentName,
        thFieldName: fieldName,
        thFieldType: fieldType,
        thFieldValue: newValue
    });
    $("#dlgDiscrete").dialog("close");
    $("#dlgChooseAgentField").dialog("close");
}

function chooseContinuous() {
    var agentName = $("#agentsName").combobox("getText");
    var fieldName = $("#fieldsName").combobox("getText");
    var fieldType = "continuous";
    var newValueLower = $("#numboxWriteLower").numberbox("getValue");
    var newValueUpper = $("#numboxWriteUpper").numberbox("getValue");
    var newValueStep = $("#numboxWriteStep").numberbox("getValue");
    var newValue = "L:" + newValueLower + ",  U:" + newValueUpper + ",  S:" + newValueStep;
    $("#tableParam").datagrid("appendRow", {
        thAgentName: agentName,
        thFieldName: fieldName,
        thFieldType: fieldType,
        thFieldValue: newValue
    });
    $("#dlgContinuous").dialog("close");
    $("#dlgChooseAgentField").dialog("close");
}

function chooseHyper() {
    var agentName = $("#agentsName").combobox("getText");
    var fieldName = $("#fieldsName").combobox("getText");
    var fieldType = "hyper";
    var newValue = $("#numboxHyperWrite").numberbox("getValue");
    $("#tableParam").datagrid("appendRow", {
        thAgentName: agentName,
        thFieldName: fieldName,
        thFieldType: fieldType,
        thFieldValue: newValue
    });
    $("#dlgHyper").dialog("close");
    $("#dlgChooseAgentField").dialog("close");
}

function openDlgChooseDiscrete(json) {
    $("#textboxReadDiscreteDefault").textbox("setValue", json.DiscreteParam.defaultValue);
    $("#discreteValues").combobox({
        data: json.DiscreteParam.acceptedValues,
    });
    $("#dlgDiscrete").dialog({modal: true});
    $("#dlgDiscrete").dialog("open");
}

function openDlgChooseContinuous(json) {
    $("#numboxReadLower").numberbox("setValue", json.ContinuousParam.lowerBound);
    $("#numboxReadUpper").numberbox("setValue", json.ContinuousParam.upperBound);
    $("#numboxReadStep").numberbox("setValue", json.ContinuousParam.acceptedStep);
    $("#numboxReadDefault").numberbox("setValue", json.ContinuousParam.defaultValue);
    $("#dlgContinuous").dialog({modal: true});
    $("#dlgContinuous").dialog("open");
}

function openDlgChooseHyper(json) {
    $("#numboxHyperReadDefault").numberbox("setValue", json.HyperParam.defaultValue);
    $("#dlgHyper").dialog({modal: true});
    $("#dlgHyper").dialog("open");
}